<?php
namespace app\api\controller\xiservice;

use app\common\controller\xiservice\XiserviceApi;
use app\common\model\xiservice\ServiceCategory as ServiceCategoryModel;
use app\common\model\xiservice\ServiceTag as ServiceTagModel;
use think\Db;
use think\Cache;
/**
 * 服务分类模块
 */
class ServiceCategory extends XiserviceApi
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];


    /**
     * @ApiTitle    (获取首页页面服务分类接口)
     * @ApiMethod   (GET)
     * @ApiRoute    (/api/xiservice.service_category/indexlist)
     * @ApiReturnParams   (name="code", type="integer", required=true, sample="0")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturnParams   (name="data", type="object", sample="{'id':'int','name':'string','image':'string'}", description="返回数据")
     */
	public function indexlist()
	{
    $cityName = $this->request->request('cityName');  

	  $list = ServiceCategoryModel::where('pid',0)->where('status',1)
    // ->where('city',$cityName)
                                ->order('weigh desc')
                                ->field(['id','name','image'])
                                // ->limit(8)
                                ->select();
	  $this->success('查询成功', $list);
	}	

    /**
     * @ApiTitle    (获取首页页面服务分类子类接口)
     * @ApiMethod   (GET)
     * @ApiRoute    (/api/xiservice.service_category/index_categorylist)
     * @ApiReturnParams   (name="code", type="integer", required=true, sample="0")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturnParams   (name="data", type="object", sample="{'id':'int','name':'string','image':'string','desc':'string',child':'object'}", description="返回数据")
     */
    public function index_categorylist()
    {
     

        //$cacheKey = 'service_category';
        //$list = Cache::get($cacheKey);
        //if(!$list) {
            $list = ServiceCategoryModel::where('index_recom',1)
                                    ->where('pid',0)->where('status',1)
                                    ->order('weigh desc')
                                    ->field(['id','name','image','desc'])
                                    ->select();
            foreach ($list as $row) {
                $row['child'] = ServiceCategoryModel::where('index_recom',1)
                                                ->where('pid',$row['id'])->where('status',1)
                                                ->order('weigh desc')
                                                ->field(['id','name','image'])
                                                ->limit(6)
                                                ->select();
            }
       //     Cache::set($cacheKey, $list, 3600);
       // }

      $this->success('查询成功', $list);
    }       
    
         //入住合同
         public function checkincontract(){
          $user_id = $this->auth->id??16;
          if(!empty($user_id)){
              $checkincontract2 =  Db::name('xiservice_contract')->where('type = 2')->find();
              $this->success('入住合同,查询成功', $checkincontract2);
          }
      }

    //   public function ordercontract(){
    //     $user_id = $this->auth->id??16;
    //     $ordercontract1 =  Db::name('xiservice_contract')->where('type = 1')->find();
    //     $this->success('下单合同,查询成功', $ordercontract1);
    // }

    public function ordercontract(){
      $user_id = $this->auth->id??16;
      if(!empty($user_id)){
          $checkincontract1 =  Db::name('xiservice_contract')->where('type = 1')->find();
          $this->success('下单合同,查询成功', $checkincontract1);
      }
  }


    /**
     * @ApiTitle    (获取分类页面服务一级分类接口)
     * @ApiMethod   (GET)
     * @ApiRoute    (/api/xiservice.service_category/indexlist)
     * @ApiReturnParams   (name="code", type="integer", required=true, sample="0")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturnParams   (name="data", type="object", sample="{'id':'int','name':'string','image':'string'}", description="返回数据")
     */
    public function categorylist()
    {
      $cityName = $this->request->request('cityName');  

      $list = ServiceCategoryModel::where('pid',0)
                                ->where('status',1)
                                // ->where('city',$cityName)
                                ->order('weigh desc')
                                ->field(['id','name','image'])
                                ->select();
      $this->success('查询成功', $list);
    }   

    /**
     * @ApiTitle    (获取分类页面服务二级分类接口)
     * @ApiMethod   (GET)
     * @ApiRoute    (/api/xiservice.service_category/indexlist)
     * @ApiReturnParams   (name="code", type="integer", required=true, sample="0")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturnParams   (name="data", type="object", sample="{'id':'int','name':'string','image':'string'}", description="返回数据")
     */
    public function categorydetail()
    {
      $id = $this->request->request('id');  
      $list = ServiceCategoryModel::where('pid',$id)
                                ->where('status',1)
                                ->order('weigh desc')
                                ->field(['id','name','image'])
                                ->select();
      $this->success('查询成功', $list);
    }   


    /**
     * @ApiTitle    (获取首页页面服务分类子类接口)
     * @ApiMethod   (GET)
     * @ApiRoute    (/api/xiservice.service_category/second_categorylist)
     * @ApiReturnParams   (name="code", type="integer", required=true, sample="0")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturnParams   (name="data", type="object", sample="{'id':'int','name':'string','image':'string','desc':'string',child':'object'}", description="返回数据")
     */
    public function second_categorylist()
    {
      $cityName = $this->request->request('cityName');  
        $list = ServiceCategoryModel::where('pid','eq',0)->where('status',1)
                                // ->where('city',$cityName)
                                    ->order('weigh desc')
                                    ->field(['*,0 as active'])
                                    ->select();

        $this->success('查询成功', $list);
    }   
    public function second_expertcategorylist()
    {
      $iscategory = $this->request->request('iscategory');  
      if($iscategory=="1")
      {
        $list = ServiceCategoryModel::where('pid','eq',80)
        ->order('weigh desc')
        ->field(['*,0 as active'])
        ->select();
      }else{

        $list = ServiceCategoryModel::where('pid','eq',80)->where('status',1)
        ->order('weigh desc')
        ->field(['*,0 as active'])
        ->select();
      }
      

        $this->success('查询成功', $list);
    }   

    /**
     * @ApiTitle    (获取服务标签接口)
     * @ApiMethod   (GET)
     * @ApiRoute    (/api/xiservice.service_category/servicetaglist)
     * @ApiReturnParams   (name="code", type="integer", required=true, sample="0")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturnParams   (name="data", type="object", sample="{'id':'int','name':'string'}", description="返回数据")
     */
    public function servicetaglist()
    {
        $list = ServiceTagModel::where('status',1)
                            ->order('weigh desc')
                            ->field(['*,0 as active'])
                            ->select();

        $this->success('查询成功', $list);        
    } 

 
}